$(function () {
	//float动态右边距
	$(".fb-li-3").click(function () {
		$('body,html').animate({ scrollTop: 0 }, 500);
	});

	$(".topbar .menu").each(function () {
		$(this).mouseenter(function () {
			$(this).addClass("menu-hover");
		})
		$(this).mouseleave(function () {
			$(this).removeClass("menu-hover");
		})
	});
	//消息框切换
	$('.msg-top li').click(function () {
		$(this).addClass("active").siblings().removeClass("active");
		if ($(this).index() == 0) {
			$('.msg-wrap').show();
			$('.account-msg').hide();
			getMessageList(2)
		} else if ($(this).index() == 1) {
			$('.msg-wrap').hide();
			$('.account-msg').show();
			getMessageList(1)
		}
	})
	//账户设置弹出
	$('#link-account .link-hd').hover(function () {
		$(this).siblings(".link-pannel").show();
	}, function () {
		$(this).siblings(".link-pannel").hide();
	});
	$('#link-account .link-pannel').hover(function () {
		$(this).show();
	}, function () {
		$(this).hide();
	});

	//header搜索弹出
	$('.header-selects').hover(function () {
		$(this).find(".header-searpop").show();
	}, function () {
		$(this).find(".header-searpop").hide();
	});
	$(".header-inputs").click(function (e) {
		e.stopPropagation();
		$(".search-result").show();
	});
	$(document).click(function () {
		$(".search-result").hide();
	});

	$(document).on('mouseenter', '.search-result li a', function (event) {
		$(this).children(".sear-history").text("删除");
		$(this).children("span").addClass("blue");
	});
	$(document).on('mouseleave', '.search-result li a', function (event) {
		$(this).children(".sear-history").text("搜索历史");
		$(this).children("span").removeClass("blue");
	});

	$('.search-triggers').hover(function () {
		$('.search-triggers').addClass("search-triggers-hover");
	}, function () {
		$('.search-triggers').removeClass("search-triggers-hover");
	});
	$('.mn-ico2').hover(function () {
		$(".cart-panel").show();
	}, function () {
		$(".cart-panel").hide();
	});
	$('.cart-panel').hover(function () {
		$('.mn-ico2').addClass("m-nav-hover"); $(".cart-panel").show();
	}, function () {
		$('.mn-ico2').removeClass("m-nav-hover"); $(".cart-panel").hide();
	});
	//左侧导航当前状态
	var curHighLightLink = $('.main h2[data-rel]').attr('data-rel');
	if (!!curHighLightLink) {
		$('.page-side-nav li[data-link="' + curHighLightLink + '"]').addClass('active');
	}
	/*两列等高
	var left_h=$('.page-side').outerHeight(true);
	var main_h=$('.main').outerHeight(true);
	var h=Math.max(left_h,main_h);
	if(left_h==h){
		$('.page-side').css('height',h)
	}else{
		$('.page-side').css('height',main_h)
	}
	//默认隐藏 鼠标指上显示
	$('.default-hide tr').hover(function(){
				$(this).find(".implicit").show();},function(){
				$(this).find(".implicit").hide();
		  });
	*/
	//checkbox级联选中
	$('.select-all').click(function () {
		if ($(this).is(':checked')) {
			$('.select-single').prop('checked', true)
		} else {
			$('.select-single').prop('checked', false)
		}
	});
	$(".select-single").click(function () {               //checkBox点击事件
		/** 判断每个二级选项是否全选中 **/
		var ia = $(".select-single");//获取这组所有的二级input标签
		var ial = ia.length;
		var countChecked1 = 0;
		for (var i = 0; i < ial; i++) {
			if (ia[i].checked == true) {
				countChecked1++;//获取checkbox被勾上的数量
			}
		}
		if (ial == countChecked1) {
			$(".select-all").prop("checked", true);
		} else {
			$(".select-all").removeAttr("checked", false);
		}
		/** 结束标志   **/
	});
	//应用图片解决左侧头像在ie下，border-radius无效问题
	var isIE = false;
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0") {
		$(".nav-lg-bg").show();
	}
	else if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE7.0") {
		$(".nav-lg-bg").show();
	}
	else if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE8.0") {
		$(".nav-lg-bg").show();
	}
	else if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE9.0") {
		$(".nav-lg-bg").show();
	}
	else if (navigator.userAgent.toLowerCase().indexOf('360se')) {
		$(".nav-lg-bg").show();
	}
	$('#news').on('click', function () {
		window.location.href = "https://member.banksteel.com/member/message_center.htm";
	})
	//轮询接口 获取消息总数图标
	var token = getCookie("user_token");
	console.log(token);
	//判断token是否存在 存在调用接口
	if (token || $('.messageCount')) {
		$("#showMessage").show();
		getMessageCount();
		setInterval(getMessageCount, 1000 * 60);
	}
});
//tabs 展现效果
function tabSlider() {
	var lineObject = $(".tab-subject-line .line");
	var wTabs = $('.tab-slider .active').outerWidth(true);
	var lTabs = $('.tab-slider .active').offset().left - $('.tab-slider').offset().left;
	lineObject.stop().animate({
		left: lTabs,
		width: wTabs
	}, 300);

	$('.tab-slider a').hover(function () {
		var currentW = $(this).outerWidth(true);
		var left = $(this).offset().left - $('.tab-slider').offset().left;
		lineObject.stop().animate({
			left: left,
			width: currentW
		}, 300);

	}, function () {
		lineObject.stop().animate({
			left: lTabs,
			width: wTabs
		}, 300);
	})
}

// 弹窗跟随屏幕高度其位置是否固定

function Autofixed(iframeId, obj) {

	$(iframeId).load(function () {
		//console.log(obj)  
		var scrollHeight = $(window).scrollTop();
		var screenH = $(window).height();
		var h = $(this).height() + 40;

		if (screenH < h) {
			$(obj.node).css({
				position: 'absolute',
				top: scrollHeight
			})
			$(iframeId).contents().find("body").height(screenH - 0)
		}
		$(window).resize(function () {
			scrollHeight = $(window).scrollTop();
			screenH = $(window).height();
			if (screenH < h) {
				$(obj.node).css({
					position: 'absolute',
					top: scrollHeight
				})
			} else {
				$(obj.node).css('position', 'fixed')
			}
		})
	});


}

$(function () {
	userLogin();
})
//获取姓名
function userLogin() {
	var token = getCookie("user_token");
	if (token) {
		$.ajax({
			type: "POST",
			url: "//login.banksteel.com/sso/verifyToken.htm",
			data: { token: token },
			success: function (result) {
				var name = result.content.loginUName;
				$(".user-name").text(name);

				//以下为判断是否为已认证会员，如果是，头部供应链服务，“票据直通车”链接修改
				// var memberId = result.content.memberId;
				// if(memberId && memberId != 0){
				// 	$("#topbar_pj").attr("href","https://e.mybank.cn/ssomode/gateway/welcome.htm?sceneKey=CROSS_ECT_BILL&bizFrom=banksteel");
				// 	$("#topbar_pj").attr("target","_blank");
				// }
			}
		});
	}
}
//设置cookie
function setCookie(c_name, value, expiredays) {
	$.cookie(c_name, value, { expires: expiredays ? expiredays : 30, domain: 'banksteel.com', path: '/' });
}
//获取cookie
function getCookie(c_name) {
	var cookieValue = $.cookie(c_name);

	if (!cookieValue) {
		cookieValue = "";
	}
	return cookieValue;
}
/*about stat*/
(function () { var a = { addCookie: function () { document.cookie = "PAGECODE=" + escape(this.uuid()) + ";expires=" + new Date("2050-1-1") + ";domain=banksteel.com" }, exists: function () { var b, c = new RegExp("(^| )PAGECODE=([^;]*)(;|$)"); return document.cookie.match(c) ? true : false }, uuid: function () { var e = []; var b = "0123456789abcdef"; for (var c = 0; c < 36; c++) { e[c] = b.substr(Math.floor(Math.random() * 16), 1) } e[14] = "4"; e[19] = b.substr((e[19] & 3) | 8, 1); e[8] = e[13] = e[18] = e[23] = "-"; var d = e.join(""); return d }, generate: function () { try { if (!this.exists()) { this.addCookie() } } catch (b) { if (console && console.error) { console.error(b) } } } }; a.generate() })();

////三级导航
//
//$(".tow-meun").click(function(){
//	$(this).each(function(){
//		$(this).parent().find(".three-meun").toggle();
//		console.log($(this).parent())
//	});
//});

var ids = [];
//获取消息
function getMessageCount() {
	$.ajax({
		type: "GET",
		url: "//member.banksteel.com/message/rest/message_user_web/unread/num",
		contentType: 'application/json;charset=utf-8',
		data: "businessType=3",
		dataType: "json",
		xhrFields: {
			withCredentials: true // 这里设置了withCredentials
		},
		success: function (res) {
			var totalCount = res.accountNum + res.businessNum;
			$('.msg-cont .trade-msg').html(res.businessNum);
			$('.msg-cont .account-num').html(res.accountNum);
			$(".messageCountDiv").css("display", "");
			if (totalCount >= 99) {
				$(".messageCount").html("99+");
			} else {
				$(".messageCount").html(totalCount);
			};
			if (res.businessNum) {
				$('.msg-wrap').show();
				$('.account-msg').hide();
				$(".msg-top li").removeClass("active");
				$(".msg-top li").eq(0).addClass('active')
				getMessageList(2)
			} else if (res.accountNum) {
				$('.msg-wrap').hide();
				$('.account-msg').show();
				$(".msg-top li").removeClass("active");
				$(".msg-top li").eq(1).addClass('active')
				getMessageList(1)
			} else {
				$('.msg-wrap').show();
				$('.account-msg').hide();
				$(".msg-top li").removeClass("active");
				$(".msg-top li").eq(0).addClass('active')
				getMessageList(2)

			}

		},
		error: function (result) {
			console.log(result);
		}
	})
};
function getMessageList(type) {
	$.ajax({
		type: "get",
		url: "//member.banksteel.com/message/rest/message_user_web",
		contentType: 'application/json;charset=utf-8',
		dataType: 'json',
		data: "businessType=3&messageType=" + type,
		xhrFields: {
			withCredentials: true // 这里设置了withCredentials
		},
		success: function (res) {
			var businessCont = "";
			ids = [];
			if (res.records.length > 0) {
				$(".msg-bottom").show()
			} else {
				$(".msg-bottom").hide()
			}
			if (res.records.length > 0) {
				for (var i = 0; i < res.records.length; i++) {
					ids.push(res.records[i].id);
					businessCont +=
						'<li  class="msg-item-li" data-id="' + res.records[i].id + '" data-jumpLink="' + res.records[i].jumpLink + '">' +
						'<dt><span>' + res.records[i].title + ' </span>' + res.records[i].showTime + '</dt>' +
						'<dd>' + res.records[i].content + '</dd>' +
						'</li>'
				}
			} else{
				businessCont = '<li  class="none-msg">暂无消息</li>'
			}
			if (type == 1) {
				$('.account-msg').html(businessCont);
			} else if (type == 2) {
				$('.msg-wrap').html(businessCont);

			}

		}
	});
};
function toRead(id, url) {
	$.ajax({
		type: "POST",
		url: "//member.banksteel.com/message/rest/message_user_web/read/" + id,
		dataType: 'json',
		xhrFields: {
			withCredentials: true // 这里设置了withCredentials
		},
		success: function (res) {
			getMessageCount();
			window.open(url);
		}
	});
};
$('.msg-bottom a').click(function () {
	var id = ids.join(',');
	$.ajax({
		type: "POST",
		xhrFields: {
			withCredentials: true // 这里设置了withCredentials
		},
		url: "//member.banksteel.com/message/rest/message_user_web/read/" + id,
		dataType: 'json',
		success: function (res) {
			getMessageCount()
		}
	});
});
$(document).on('click', '.msg-item-li', function () {
	toRead($(this).attr('data-id'), $(this).attr('data-jumpLink'))
});
